﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.TemplateWizard;
using EnvDTE;
using EnvDTE80;

namespace NHibernateItemTemplate
{
    public class MappingWizard : IWizard
    {

        #region IWizard Members

        public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem)
        {
        }

        public void ProjectFinishedGenerating(EnvDTE.Project project)
        {
        }

        public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
        {
            projectItem.Properties.Item("BuildAction").Value = 3; // Embedded Resources
        }

        public void RunFinished()
        {
        }

        public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
        {
            if (automationObject is DTE2)
            {
                DTE2 application = automationObject as DTE2;

                SelectedItem item = application.SelectedItems.Item(1);
                Project project = null;
                if (item.ProjectItem != null)
                {
                    project = item.ProjectItem.ContainingProject;
                }
                else if (item.Project != null)
                {
                    project = item.Project;
                }
                if (project != null)
                {
                    replacementsDictionary.Add("$assemblyname$", project.Properties.Item("AssemblyName").Value.ToString());
                }
                else
                {
                    throw new ApplicationException("Could not determin project");
                }

            }
            else
            {
                throw new ArgumentException("utomationObject is not of type DTE2");
            }
        }

        public bool ShouldAddProjectItem(string filePath)
        {
            return true;
        }

        #endregion
    }
}
